import { Map } from "immutable"

import * as actionTypes from './constants'

const defaultState = Map({
  qrcode: '',
  status: '',
  loginStatus: false,
  cookie: '',
  isShow: false,
  userId: '',
  detail: { id: '12312312' },
  isLogin: false
})


function reducer(state = defaultState, action) {
  switch (action.type) {
    case actionTypes.CHAGNE_QRCODE_KEY:
      return state.set('qrCodeKey', action.qrcode.unikey)
    case actionTypes.CHAGNE_QRCODE_BASE:
      return state.set('qrcodeBase', action.qrcode.data)
    case actionTypes.CHANGE_QRCODE_STATUS:
      return state.set('qrcodeStatus', action.status)
    case actionTypes.CHANGE_LOGIN_STATUS:
      return state.set('loginStatus', action.loginStatus)
    case actionTypes.CHANGE_LOGIN_COOKIE:
      return state.set('useCookie', action.cookie)
    case actionTypes.CHANGE_LOGIN_ISSHOW:
      return state.set('isShow', !state.get('isShow'))
    case actionTypes.CHANGE_USER_ID:
      return state.set('userId', action.id)
    case actionTypes.CHANGE_USER_DETAIL:
      console.log('执行CHANGE_USER_DETAIL', action);
      return state.set('detail', action.detail)
    case actionTypes.CHANGE_IS_LOGIN:
      console.log('执行CHANGE_IS_LOGIN', action);
      return state.set('isLogin', action.value)
    default:
      return state
  }
}

export default reducer